﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace DoAnSE104
{
    public partial class frmLogin : Form
    {
        
        public frmLogin()
        {
            InitializeComponent();
        }
        DataTable dt;
        SqlConnection con = new SqlConnection(@"Data Source=VENUIT\SQLEXPRESS;Initial Catalog=QLSOTIETKIEM;Integrated Security=True");

        private DataTable CheckLogin(string TenDangNhap, string MatKhau)
        {
            if (con.State == ConnectionState.Closed)
            {
                con.Open();
            }


            string sql = "PHANQUYEN_ktra";
            SqlCommand comd = new SqlCommand(sql, con);
            comd.CommandType = CommandType.StoredProcedure;
            comd.Parameters.Add(new SqlParameter("username", SqlDbType.NVarChar)).Value = TenDangNhap;
            comd.Parameters.Add(new SqlParameter("password", SqlDbType.VarChar)).Value = MatKhau;
            SqlDataAdapter da = new SqlDataAdapter(comd);
            dt = new DataTable();
            da.Fill(dt);
            con.Close();


            return dt;
        }
        private void btLogin_Click(object sender, EventArgs e)
        {

            con.Open();
            dt = new DataTable();
            dt = CheckLogin(txtUser.Text, txtPass.Text);
            if (dt.Rows.Count > 0)
            {
                this.Hide();
                frmManHinhChinh frmM = new frmManHinhChinh();
                frmM.Show();
            }
            else
            {
                MessageBox.Show("Tài khoản không tồn tại\n Mời bạn nhập lại", "Thông Báo",MessageBoxButtons.OK);
               // this.txtUser.Clear();
                //this.txtPass.Clear();
                
               // this.txtPass.Focus();
               // this.txtUser.Focus();
            }
        }

        private void btReset_Click(object sender, EventArgs e)
        {
            this.txtUser.Clear();
            this.txtPass.Clear();
            this.txtPass.Focus();
            this.txtUser.Focus();
          
        }

        private void frmLogin_Load(object sender, EventArgs e)
        {
            this.AcceptButton = btLogin;
        }

        

        private void btLogin_Click()
        {
            throw new NotImplementedException();
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {

        }
    }
}
